import React, { useEffect, useState, useRef } from 'react';
import Left from './left';
import Right from './right';

import { taskInspectStatistics } from '@/services/bimServices';

const StatisticsDataContext = React.createContext();
StatisticsDataContext.displayName = 'StatisticsDataContext';

export function useStatisticsData() {
  const context = React.useContext(StatisticsDataContext);
  if (context === void 0) {
    throw new Error('必须配合userprovider使用');
  }
  return context;
}

function StatisticsDataProvider({ children }) {
  const [curData, setCurData] = useState(null);
  const value = [curData, setCurData];
  return <StatisticsDataContext.Provider value={value}>{children}</StatisticsDataContext.Provider>;
}

export async function updateStatisticsData(dataSetter, curProjId) {
  if (!curProjId) {
    return;
  }
  try {
    const data = await taskInspectStatistics(curProjId);
    dataSetter(data);
    return data;
  } catch (error) {}
}

//--------------------------------

export default function QualityAndSafety() {
  // useEffect(() => {
  //   if (dangerRouteref.current) {
  //     dangerRouteref.current.visible = true;
  //   }
  //   return () => {
  //     if (dangerRouteref.current) {
  //       dangerRouteref.current.visible = false;
  //     }
  //   };
  // }, []);

  return (
    <StatisticsDataProvider>
      <Left />
      <Right />
    </StatisticsDataProvider>
  );
}
